package com.vmove.childtrain.common;

import android.app.Application;
import android.os.Handler;
import android.os.Looper;

import com.alibaba.fastjson.JSONObject;
import com.lzy.okgo.OkGo;
import com.tencent.bugly.crashreport.CrashReport;
import com.vmove.childtrain.utils.AutoUtils;

import cn.wch.ch34xuartdriver.CH34xUARTDriver;

public class AppContext extends Application {

    private static AppContext app;

    /**
     * 主线程ID
     */
    private static int mMainThreadId = -1;
    /**
     * 主线程ID
     */
    private static Thread mMainThread;
    /**
     * 主线程Handler
     */
    private static Handler mMainThreadHandler;
    /**
     * 主线程Looper
     */
    private static Looper mMainLooper;

    public static  CH34xUARTDriver driver;

    public AppContext() {
        app = this;
    }

    public static synchronized AppContext getInstance() {
        if (app == null) {
            app = new AppContext();
        }
        return app;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mMainThreadId = android.os.Process.myTid();
        mMainThread = Thread.currentThread();
        mMainThreadHandler = new Handler();
        mMainLooper = getMainLooper();
        app = this;
        initOkGo();
        CrashReport.initCrashReport(getApplicationContext(), "85ed735896", false);
//        Bugly.init(getApplicationContext(), "d14a690e35", false);
    }

    private void initOkGo() {
        OkGo.getInstance().init(this);
    }

    /**
     * 获取主线程ID
     */
    public static int getMainThreadId() {
        return mMainThreadId;
    }

    /**
     * 获取主线程
     */
    public static Thread getMainThread() {
        return mMainThread;
    }

    /**
     * 获取主线程的handler
     */
    public static Handler getMainThreadHandler() {
        return mMainThreadHandler;
    }

}